package com.lyz.dataStructure.xiaozhao2018;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 11:52
 * @Description:
 **/

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/4/14 11:52
 *@Description:
 **/

/*
给定一个无序数组，包含正数、负数和0，要求从中找出3个数的乘积，使得乘积最大，要求时间复杂度：O(n)，空间复杂度：O(1)


3 4 1 2

24
 */
public class Test1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        System.out.println("请输入数组：");
        while (input.hasNext()) {
            String st = input.nextLine();
            String[] st2 = st.split(" ");
            int[] arr = new int[st2.length];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = Integer.parseInt(st2[i]);
            }
            int sum = 0;
            for (int i = 0; i < arr.length - 1; i++) {
                for (int j = 0; j < arr.length - i - 1; j++) {
                    if (arr[j] > arr[j + 1]) {
                        int num = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = num;
                    }
                }
            }
            sum = arr[arr.length - 1] * arr[arr.length - 2] * arr[arr.length - 3];
            System.out.println(sum);
        }
    }
}
